package com.sjz.bookmark.mysql;

import com.intellij.icons.AllIcons;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

public class BookmarkTreeCellRenderer extends ColoredTreeCellRenderer {
    @Override
    public void customizeCellRenderer(@NotNull JTree tree, Object value,
                                    boolean selected, boolean expanded,
                                    boolean leaf, int row, boolean hasFocus) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        if (node.getUserObject() == null) {
            return;
        }
        BookmarkRecord bookmarkRecord = (BookmarkRecord)node.getUserObject();

        if (true) {
            // 分类节点样式
            append(bookmarkRecord.getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
            setIcon(AllIcons.Nodes.Folder);
        } else {
            // 书签节点样式
            append(bookmarkRecord.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
            setIcon(AllIcons.Nodes.Bookmark);
        }
    }
}